package com.gpjcjl.entity;

import android.text.TextUtils;

import com.base.lib.SharedHelper;
import com.gpjcjl.Config;
import com.gpjcjl.util.MathUtil;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Locale;
import java.util.Objects;

public class SettingProfile {

    /**
     * 制造单位
     */
    public static String getProduce() {
        return SharedHelper.getInstance().getString(Config.DEFAULT_PRODUCE, null);
    }

    public static void setProduce(String produce) {
        SharedHelper.getInstance().put(Config.DEFAULT_PRODUCE, produce);
    }

    /**
     * 钢瓶编号 录入/自动
     *
     * @return
     */
    public static String getNumType() {
        return SharedHelper.getInstance().getString(Config.DEFAULT_NUM_TYPE, "自动");
    }

    public static void setNumType(String numType) {
        SharedHelper.getInstance().put(Config.DEFAULT_NUM_TYPE, numType);
    }

    public static String getProduceTime() {
        String timeType = getProduceTimeType();
        String startTime = getProduceTimeStart();
        String endTime = getProduceTimeEnd();
        String produceTime = null;
        try {
            if ("自动".equals(timeType) && !TextUtils.isEmpty(startTime) && !TextUtils.isEmpty(endTime)) {
                SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd", Locale.getDefault());
                long min = Objects.requireNonNull(format.parse(startTime)).getTime();
                long max = Objects.requireNonNull(format.parse(endTime)).getTime();
                //从时间范围内取一天
                long s = MathUtil.getRandomLong(min, max);
                produceTime = format.format(new Date(s));
            }
        } catch (ParseException e) {
            e.printStackTrace();
        }
        return produceTime;
    }

    /**
     * 检测时间 录入/自动
     *
     * @return
     */
    public static String getProduceTimeType() {
        return SharedHelper.getInstance().getString(Config.DEFAULT_PRODUCE_DATE, "录入");
    }

    public static void setProduceTimeType(String produceTime) {
        SharedHelper.getInstance().put(Config.DEFAULT_PRODUCE_DATE, produceTime);
    }

    public static String getProduceTimeStart() {
        return SharedHelper.getInstance().getString(Config.DEFAULT_PRODUCE_DATE_START, null);
    }

    public static String getProduceTimeEnd() {
        return SharedHelper.getInstance().getString(Config.DEFAULT_PRODUCE_DATE_END, null);
    }

    /**
     * 外表宏观检测 合格/不合格
     *
     * @return
     */
    public static String getAround() {
        return SharedHelper.getInstance().getString(Config.DEFAULT_AROUND, "合格");
    }

    public static void setAround(String around) {
        SharedHelper.getInstance().put(Config.DEFAULT_AROUND, around);
    }

    public static String getWall() {
        String wallType = getWallType();
        String wallMin = getWallMin();
        String wallMax = getWallMax();
        String wall = null;
        if ("自动".equals(wallType) && !TextUtils.isEmpty(wallMin) && !TextUtils.isEmpty(wallMax)) {
            double s = MathUtil.getRandomDouble(wallMin, wallMax);
            wall = String.valueOf(s);
        }
        return wall;
    }

    /**
     * 最小壁厚 录入/自动
     *
     * @return
     */
    public static String getWallType() {
        return SharedHelper.getInstance().getString(Config.DEFAULT_WALL, "录入");
    }

    public static void setWallType(String wall) {
        SharedHelper.getInstance().put(Config.DEFAULT_WALL, wall);
    }

    public static String getWallMin() {
        return SharedHelper.getInstance().getString(Config.DEFAULT_WALL_MIN, null);
    }

    public static String getWallMax() {
        return SharedHelper.getInstance().getString(Config.DEFAULT_WALL_MAX, null);
    }

    public static String getWeight() {
        String weightType = getWeightType();
        String weightMin = getWeightMin();
        String weightMax = getWeightMax();
        String weight = null;
        if ("自动".equals(weightType) && !TextUtils.isEmpty(weightMin) && !TextUtils.isEmpty(weightMax)) {
            double s = MathUtil.getRandomDouble(weightMin, weightMax);
            weight = String.valueOf(s);
        }
        return weight;
    }

    /**
     * 重量 录入/自动
     *
     * @return
     */
    public static String getWeightType() {
        return SharedHelper.getInstance().getString(Config.DEFAULT_WEIGHT, "录入");
    }

    public static void setWeightType(String weight) {
        SharedHelper.getInstance().put(Config.DEFAULT_WEIGHT, weight);
    }

    public static String getWeightMin() {
        return SharedHelper.getInstance().getString(Config.DEFAULT_WEIGHT_MIN, null);
    }

    public static String getWeightMax() {
        return SharedHelper.getInstance().getString(Config.DEFAULT_WEIGHT_MAX, null);
    }

    /**
     * 瓶阀检测  合格/不合格
     *
     * @return
     */
    public static String getBottle() {
        return SharedHelper.getInstance().getString(Config.DEFAULT_BOTTLE, "合格");
    }

    public static void setBottle(String bottle) {
        SharedHelper.getInstance().put(Config.DEFAULT_BOTTLE, bottle);
    }

    /**
     * 水压检测  合格/不合格
     *
     * @return
     */
    public static String getWater_gage() {
        return SharedHelper.getInstance().getString(Config.DEFAULT_WATER_GAGE, "合格");
    }

    public static void setWater_gage(String water_gage) {
        SharedHelper.getInstance().put(Config.DEFAULT_WATER_GAGE, water_gage);
    }

    /**
     * 气密检测 合格/不合格
     *
     * @return
     */
    public static String getAirtight() {
        return SharedHelper.getInstance().getString(Config.DEFAULT_AIRTIGHT, "合格");
    }

    public static void setAirtight(String airtight) {
        SharedHelper.getInstance().put(Config.DEFAULT_AIRTIGHT, airtight);
    }

    /**
     * 检测结论
     *
     * @return
     */
    public static String getEpilog() {
        return SharedHelper.getInstance().getString(Config.DEFAULT_EPILOG, null);
    }

    public static void setEpilog(String epilog) {
        SharedHelper.getInstance().put(Config.DEFAULT_EPILOG, epilog);
    }

    /**
     * 报废原因
     *
     * @return
     */
    public static String getScrap() {
        return SharedHelper.getInstance().getString(Config.DEFAULT_SCRAP, null);
    }

    public static void setScrap(String scrap) {
        SharedHelper.getInstance().put(Config.DEFAULT_SCRAP, scrap);
    }
}
